val nameStr = "live_forest_2022"
val scalaVersionStr = "2.13.8"
version := "0.1"

scalaVersion := scalaVersionStr

lazy val server = (project in file("server")).settings(commonSettings).settings(
  name := s"${nameStr}_server",
  version := "1.0",
  libraryDependencies ++= Seq(
    guice,
    specs2 % Test,
    ehcache,
    "com.typesafe.play" %% "play-slick" % "4.0.2",
    "com.typesafe.slick" %% "slick-codegen" % "3.3.2",
    "mysql" % "mysql-connector-java" % "5.1.25",
    "com.github.tototoshi" %% "slick-joda-mapper" % "2.4.1",
    "commons-io" % "commons-io" % "2.5",
    "org.apache.poi" % "poi-ooxml" % "3.15",
    "org.apache.commons" % "commons-math3" % "3.6.1",
    "com.aliyun" % "aliyun-java-sdk-core" % "3.7.1",
    "com.aliyun" % "aliyun-java-sdk-dysmsapi" % "1.1.0",
    "com.typesafe.play" %% "play-joda-forms" % "2.7.3",
    "org.apache.xmlgraphics" % "batik-codec" % "1.10",
    "org.jxls" % "jxls" % "2.4.7",
    "com.itextpdf" % "itext7-core" % "7.1.4",
    "com.hhandoko" %% "play28-scala-pdf" % "4.3.0",
    "net.logstash.logback" % "logstash-logback-encoder" % "5.3",
    "org.scala-lang.modules" %% "scala-parallel-collections" % "0.2.0",
    "org.apache.commons" % "commons-lang3" % "3.6",
    "javax.mail" % "mail" % "1.4.7",
    "com.lihaoyi" %% "upickle" % "2.0.0",
    "org.typelevel" %% "cats-core" % "2.0.0",
    "com.beachape" %% "enumeratum" % "1.7.0"
  ),
  scalacOptions ++= {
    Seq(
      "-Ymacro-annotations"
    )
  }
).enablePlugins(PlayScala).dependsOn(sharedJvm)

val reactVersion = "17.0.2"

lazy val client = (project in file("client")).settings(commonSettings).settings(
  name := "client",
  useYarn := true,
  webpackDevServerPort := 8080,
  webpack / version := "4.40.2",
  startWebpackDevServer / version := "3.11.2",
  webpackResources := baseDirectory.value / "webpack" * "*",
  fastOptJS / webpackConfigFile := Some(baseDirectory.value / "webpack" / "webpack-fastopt.config.js"),
  fullOptJS / webpackConfigFile := Some(baseDirectory.value / "webpack" / "webpack-opt.config.js"),
  fullOptJS / webpackEmitSourceMaps := false,
  Test / webpackConfigFile := Some(baseDirectory.value / "webpack" / "webpack-core.config.js"),
  fastOptJS / webpackDevServerExtraArgs := Seq("--inline", "--hot"),
  fastOptJS / webpackBundlingMode := BundlingMode.LibraryOnly(),
  fastOptJS / webpackEmitSourceMaps := false,
  libraryDependencies ++= Seq(
    "com.lihaoyi" %%% "scalatags" % "0.11.1",
    "me.shadaj" %%% "slinky-web" % "0.7.2",
    "me.shadaj" %%% "slinky-hot" % "0.7.2",
    "org.scala-js" %%% "scala-js-macrotask-executor" % "1.0.0",
    "com.lihaoyi" %%% "upickle" % "2.0.0",
    "com.softwaremill.quicklens" %%% "quicklens" % "1.6.1",
    "com.softwaremill.sttp.client3" %%% "core" % "3.8.3",
    "com.softwaremill.sttp.client3" %%% "upickle" % "3.8.3",
    "com.beachape" %%% "enumeratum" % "1.7.0",
    "io.scalaland" %%% "chimney" % "0.6.2",
  ),
  Compile / npmDependencies ++= Seq(
    "d3" -> "4.13.0",
    "react-hook-form" -> "7.37.0",
    "react-select" -> "5.4.0",
    "jquery" -> "3.5.0",
    "react" -> reactVersion,
    "react-dom" -> reactVersion,
    "react-proxy" -> "1.1.8",
    "file-loader" -> "6.2.0",
    "style-loader" -> "2.0.0",
    "css-loader" -> "5.2.6",
    "html-webpack-plugin" -> "4.5.1",
    "copy-webpack-plugin" -> "6.4.0",
    "webpack-merge" -> "5.8.0",
    "react-router-dom" -> "6.2.1",
    "react-i18next" -> "11.16.2",
    "i18next" -> "21.6.14",
    "bootstrap-datepicker" -> "1.6.4",
    "react-bootstrap" -> "1.6.4",
    "bootstrap-sweetalert" -> "1.0.1",
    "layer-src" -> "3.5.1",
    "bootstrapvalidator" -> "0.5.4",
    "nprogress" -> "0.2.0",
    "react-transition-group" -> "4.4.2",
    "dom-helpers" -> "5.2.1",
    "bootstrap" -> "4.6.1",
    "qrcode" -> "1.5.0",
    "jszip" -> "3.7.1",
    "react-image-lightbox" -> "5.1.4",
    "select2" -> "4.0.13",
    "plotly.js-basic-dist-min" -> "2.11.1",
    "knockout" -> "3.5.1",
    "font-awesome" -> "4.7.0",
    "highcharts" -> "10.1.0",
    "bootstrap-3-typeahead" -> "4.0.2",
    "@types/react" -> reactVersion,
    "jquery-backstretch"->"2.1.16",
    "@hookform/resolvers" -> "2.8.5",
    "yup" -> "0.32.11",
    "react-draggable"->"4.4.5",
    "moment"->"2.29.4",
  ),
  stFlavour := Flavour.Slinky,
  stIgnore := List(
    "d3",
    "react-hook-form",
    "react-select",
    "jquery",
    "react-dom",
    "react-proxy",
    "file-loader",
    "style-loader",
    "css-loader",
    "html-webpack-plugin",
    "copy-webpack-plugin",
    "webpack-merge",
    "react-router-dom",
    "react-i18next",
    "i18next",
    "bootstrap-datepicker",
    "react-bootstrap",
    "bootstrap-sweetalert",
    "layer-src",
    "bootstrapvalidator",
    "nprogress",
    "react-transition-group",
    "dom-helpers",
    "bootstrap",
    "qrcode",
    "jszip",
    "react-image-lightbox",
    "select2",
    "plotly.js-basic-dist-min",
    "knockout",
    "font-awesome",
    "highcharts",
    "bootstrap-3-typeahead",
    "jquery-backstretch",
    "@hookform/resolvers",
    "yup",
    "react-draggable",
    "moment"
  ),
  scalacOptions ++= {
    Seq(
      "-Ymacro-annotations"
    )
  },
  webpackBundlingMode := BundlingMode.LibraryAndApplication(),
  webpackConfigFile := Some(baseDirectory.value / "my.custom.webpack.config.js")
).enablePlugins(ScalaJSBundlerPlugin, ScalablyTypedConverterPlugin).dependsOn(sharedJs)

lazy val shared = crossProject(JSPlatform, JVMPlatform)
  .crossType(CrossType.Pure)
  .in(file("shared"))
  .settings(commonSettings)
  .settings(
    scalacOptions ++= {
      Seq("-Ymacro-annotations")
    },
    libraryDependencies ++= Seq(
      "com.lihaoyi" %% "upickle" % "2.0.0",
      "com.beachape" %% "enumeratum" % "1.7.0",
      "joda-time" % "joda-time" % "2.10.5",
    )
  )
lazy val sharedJvm = shared.jvm
lazy val sharedJs = shared.js

lazy val commonSettings = Seq(
  scalaVersion := scalaVersionStr,
  resolvers ++= Seq(
    Resolver.sonatypeRepo("snapshots")
  )
)

addCommandAlias("dev", ";client/fastOptJS::startWebpackDevServer;~client/fastOptJS")
addCommandAlias("stop-dev", ";client/fastOptJS::stopWebpackDevServer")
addCommandAlias("build", "client/fullOptJS::webpack")
